package servlet;

import java.io.IOException;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dto.Post;
import schoolDAO.PostDAO;

public class RegisterPostServlet extends HttpServlet {

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req,resp);
	}
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		    String pId = req.getParameter("pId");
			String pName = req.getParameter("pName");
						
			PostDAO pd = new PostDAO();
			Post p = new Post();
			p.setpId(pId);
			p.setpName(pName);
			boolean flag = pd.insert(p);
			Vector v=pd.findAllPost();
			HttpSession session= req.getSession();
			session.setAttribute("allPost",v);
			if(flag){
				resp.sendRedirect(req.getContextPath()+"/admin/allpost.jsp");
			}else{
				resp.sendRedirect(req.getContextPath()+"/error.html");
			}		
	}
	
}
